import Vue from "vue";
import store from "@/store";

function hasPerm(permName) {
  const roles = store.getters.roles;
  return roles.some(role => role.permNameList.includes(permName))
}

Vue.prototype.$hasPerm = hasPerm;

Vue.directive("perm", {
  bind: function(el, binding, vnode) {
    const permName = binding.arg;
    if (!hasPerm(permName)) {
      Vue.nextTick(function () {
        if (el.parentNode == null) {
          el.style.display = "none";
        } else {
          el.parentNode.removeChild(el);
        }
      })
    }
  }
});
